#include<math.h> #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; void Rd(ll&res){ res=0;char c; while(c=getchar(),c<48); do res=res*10+(c&15); while(c=getchar(),c>47); } struct node{ ll x,y; }pos1,pos2; void dfs(node &cur,ll x,ll y,ll len,ll id,ll idl,ll idr,int type){ if(len==1){ cur=(node){x,y}; return; } ll cnt=(idr-idl+1)/4; if(type==1){ if(id<=cnt+idl-1)dfs(cur,x,y,len/2,id,idl,cnt+idl-1,2); else if(id<=cnt*2+idl-1)dfs(cur,x,y+len/2,len/2,id,cnt+idl,cnt*2+idl-1,1); else if(id<=cnt*3+idl-1)dfs(cur,x+len/2,y+len/2,len/2,id,cnt*2+idl,cnt*3+idl-1,1); else dfs(cur,x+len/2,y,len/2,id,cnt*3+idl,cnt*4+idl-1,4); }else if(type==2){ if(id<=cnt+idl-1)dfs(cur,x,y,len/2,id,idl,cnt+idl-1,1); else if(id<=cnt*2+idl-1)dfs(cur,x+len/2,y,len/2,id,cnt+idl,cnt*2+idl-1,2); else if(id<=cnt*3+idl-1)dfs(cur,x+len/2,y+len/2,len/2,id,cnt*2+idl,cnt*3+idl-1,2); else dfs(cur,x,y+len/2,len/2,id,cnt*3+idl,cnt*4+idl-1,3); }else if(type==3){ if(id<=cnt+idl-1)dfs(cur,x+len/2,y+len/2,len/2,id,idl,cnt+idl-1,4); else if(id<=cnt*2+idl-1)dfs(cur,x+len/2,y,len/2,id,cnt+idl,cnt*2+idl-1,3); else if(id<=cnt*3+idl-1)dfs(cur,x,y,len/2,id,cnt*2+idl,cnt*3+idl-1,3); else dfs(cur,x,y+len/2,len/2,id,cnt*3+idl,cnt*4+idl-1,2); }else{ if(id<=cnt+idl-1)dfs(cur,x+len/2,y+len/2,len/2,id,idl,cnt+idl-1,3); else if(id<=cnt*2+idl-1)dfs(cur,x,y+len/2,len/2,id,cnt+idl,cnt*2+idl-1,4); else if(id<=cnt*3+idl-1)dfs(cur,x,y,len/2,id,cnt*2+idl,cnt*3+idl-1,4); else dfs(cur,x+len/2,y,len/2,id,cnt*3+idl,cnt*4+idl-1,1); } } ll T,f[35],f2[35]; int main(){ Rd(T); f[0]=f2[0]=1; for(int i=1;i<=31;i++) f[i]=f[i-1]*2,f2[i]=f2[i-1]*4; for(int i=1;i<=T;i++){ ll n,id1,id2; Rd(n),Rd(id1),Rd(id2); dfs(pos1,1,1,f[n],id1,1,f2[n],2); dfs(pos2,1,1,f[n],id2,1,f2[n],2); ll daltx=abs(pos1.x-pos2.x)*10; ll dalty=abs(pos1.y-pos2.y)*10; long double ans=sqrt((long double)daltx*daltx+(long double)dalty*dalty); ll temp=ans; cout<<((ans>=temp+0.5)?(temp+1):temp)<<endl; } return 0; }
|